package cn.edu.ujn.booksshop.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.edu.ujn.booksshop.dao.Payment;
import cn.edu.ujn.booksshop.dao.Review;
import cn.edu.ujn.booksshop.service.IReviewService;
import cn.edu.ujn.util.Page;

@Controller
public class ReviewController {

	@Autowired
	private IReviewService reviewService;
	@GetMapping("review/list.action")
	public String list(Model model,@RequestParam (defaultValue = "1")  Integer page ,@RequestParam(defaultValue ="10")  Integer rows) {
		Page<Review> selectAll = this.reviewService.selectAll(page, rows);
		model.addAttribute("page", selectAll);
		return "review";
	}
	@RequestMapping("/review/create.action")
	@ResponseBody
	public String create(Review review) {
		review.setIsdeleted(false);
		int insert = this.reviewService.insert(review);
		if(insert>0) {
			return "OK";
		}else {
			return "FAIL";
		}
	}
	@RequestMapping("/review/delete.action")
	@ResponseBody
	public String delete(Integer id) {
		int delete = this.reviewService.deleteByPrimaryKey(id);
		if(delete>0) {
			return "OK";
		}else {
			return "FAIL";
		}
	}
	
	@RequestMapping("/review/update.action")
	@ResponseBody
	public String update(Review review) {
		int updateByPrimaryKeySelective = this.reviewService.updateByPrimaryKeySelective(review);
		if(updateByPrimaryKeySelective>0) {
			return "OK";
		}else {
			return "FAIL";
		}
	}
	
	@RequestMapping("/review/getReviewById.action")
	@ResponseBody
	public Review getReviewById(Integer id) {
	    Review review = reviewService.getReviewById(id);
	    return review;
	}
}
